package com.heima.article.service.impl;

import com.heima.article.mapper.ApArticleContentMapper;
import com.heima.article.mapper.ApArticleMapper;

import com.heima.article.service.ApUserRealnameService;
import com.heima.model.admin.vo.ApArticleVo;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleContent;

import com.heima.model.common.dtos.ResponseResult;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Slf4j
@Service
public class ApUserRealnameServiceImpl implements ApUserRealnameService {


    @Autowired
    private ApArticleMapper apArticleMapper;
    @Autowired
    private ApArticleContentMapper apArticleContentMapper;


    //文章人工审核 成功 新增文章已发布
    @Override
    public ResponseResult authPass(ApArticleVo vo) {
        //新增两张表
        //1.新增（ap_article）
        ApArticle apArticle = new ApArticle();
        BeanUtils.copyProperties(vo, apArticle);
        apArticleMapper.insert(apArticle);
        // 2.新增（ap_article_content）#
        ApArticleContent apArticleContent = new ApArticleContent();
        apArticleContent.setContent(vo.getContent());
        apArticleContent.setArticleId(vo.getId());
        apArticleContentMapper.insert(apArticleContent);
        return ResponseResult.okResult(apArticle);
    }
}
